package leetcode.offer;

/**
 * ClassName: TwoSum
 * Description: leetcode-剑指offer 57 和为s的两个数字
 * date: 2021-11-08 23:30
 *
 * @author liyifan
 */
public class TwoSum {
    public int[] twoSum(int[] nums, int target) {
        int left = 0;
        int right = nums.length - 1;
        int mid;
        while (left < right) {
            mid = nums[left] + nums[right];
            if (target == mid) {
                return new int[]{nums[left], nums[right]};
            } else if (mid > target) {
                right = right - 1;
            } else {
                left = left + 1;
            }
        }
        return new int[]{};
    }
}
